import request from '@/utils/request'
import type {
  ProtocolInfo,
  ProtocolQueryParams,
  ProtocolListResponse,
  ProtocolDetailResponse,
  ProtocolOperationResponse,
  ProtocolFormData
} from './types'

// 获取协议列表
export function getProtocolList(params: ProtocolQueryParams): Promise<ProtocolListResponse> {
  return request({
    url: '/protocol/protocolVersion/list',
    method: 'get',
    params
  })
}

// 获取协议详情
export function getProtocolDetail(protocolId: string | number): Promise<ProtocolDetailResponse> {
  return request({
    url: `/protocol/protocolVersion/${protocolId}`,
    method: 'get'
  })
}

// 新增协议
export function addProtocol(data: ProtocolFormData): Promise<ProtocolOperationResponse> {
  return request({
    url: '/protocol/protocolVersion',
    method: 'post',
    data
  })
}

// 修改协议
export function updateProtocol(data: ProtocolFormData): Promise<ProtocolOperationResponse> {
  return request({
    url: '/protocol/protocolVersion',
    method: 'put',
    data
  })
}

// 删除协议
export function deleteProtocol(protocolIds: string): Promise<ProtocolOperationResponse> {
  return request({
    url: `/protocol/protocolVersion/${protocolIds}`,
    method: 'delete'
  })
}

// 导出协议
export function exportProtocol(params: ProtocolQueryParams): Promise<any> {
  return request({
    url: '/protocol/protocolVersion/export',
    method: 'post',
    data: params,
    responseType: 'blob'
  })
}